<?php


namespace app\api\model;


use app\api\model\Banner as BannerModel;
use think\Db;
use think\Exception;
use think\Model;

class Banner extends BaseModel
{
    protected $hidden = ['delete_time', 'update_time'];

    public function items() {
        return $this->hasMany('banner_item', 'banner_id', 'id');
    }

    public static function getBannerById($id) {

        $banner = self:: with(['items','items.img'])->find($id);
//        $banner->visible(['id']);
//        $banner->hidden(['delete_time', 'update_time']);
//        $data = $banner->toArray();
//        unset($data['delete_time']);
//        $result = Db::query('select * from banner_item where banner_id = ?', [$id]);
//        $result = Db::table('banner_item')->where('banner_id', '=', $id)->select();
        return $banner;
    }

}